Skip to content

Commit 1e6877f

Browse files
authored
Merge pull request #6638 from emilghittasv/playwright-add-tests
Playwright further extend test coverage over contributor discussions forum threads
2 parents e96f358 + acc0ff3 commit 1e6877f

File tree

6 files changed

+698
-7
lines changed

6 files changed

+698
-7
lines changed

playwright_tests/flows/contributor_threads_flows/contributor_threads_flows.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import re
22
from playwright.sync_api import Page
33
from playwright_tests.core.utilities import Utilities
4+
from playwright_tests.pages.contribute.contribute_pages.contributor_discussions.\
5+
delete_thread_post_page import DeleteThreadPostPage
6+
from playwright_tests.pages.contribute.contribute_pages.contributor_discussions.\
7+
edit_thread_post_page import EditThreadPostPage
48
from playwright_tests.pages.contribute.contribute_pages.contributor_discussions.\
59
edit_thread_title_page import EditThreadTitle
610
from playwright_tests.pages.contribute.contribute_pages.contributor_discussions\
@@ -18,6 +22,8 @@ def __init__(self, page: Page):
1822
self.forum_discussions_page = ForumDiscussionsPage(page)
1923
self.forum_thread_page = ForumThreadPage(page)
2024
self.edit_thread_title_page = EditThreadTitle(page)
25+
self.edit_post_page = EditThreadPostPage(page)
26+
self.delete_thread_post_page = DeleteThreadPostPage(page)
2127

2228
def post_a_new_thread(self, thread_title: str, thread_body: str, cancel=False) -> str:
2329
"""
@@ -59,6 +65,17 @@ def post_thread_reply(self, reply_body: str) -> str:
5965

6066
return re.search(r'post-(\d+)', self.utilities.get_page_url()).group(1)
6167

68+
def quote_thread_post(self, post_id: str) -> str:
69+
"""
70+
Quote a thread post.
71+
Args:
72+
post_id (str): The ID of the post to be quoted.
73+
"""
74+
self.forum_thread_page.click_on_quote_option(post_id)
75+
self.forum_thread_page.click_on_post_reply_button()
76+
77+
return re.search(r'post-(\d+)', self.utilities.get_page_url()).group(1)
78+
6279
def edit_thread_title(self, new_title: str):
6380
"""
6481
Edit the title of a thread.
@@ -69,6 +86,34 @@ def edit_thread_title(self, new_title: str):
6986
self.edit_thread_title_page.fill_into_thread_title_input_field(new_title)
7087
self.edit_thread_title_page.click_on_update_thread_button()
7188

89+
def edit_thread_post(self, post_id: str, new_thread_post: str):
90+
"""
91+
Edit the thread post.
92+
Args:
93+
post_id (str): The ID of the post to be edited.
94+
new_thread_post (str): The new post for the thread.
95+
"""
96+
self.forum_thread_page.click_on_edit_this_post_option(post_id)
97+
self.edit_post_page.add_text_inside_the_edit_post_textarea(new_thread_post)
98+
self.edit_post_page.click_on_update_post_button()
99+
100+
def delete_thread_post(self, post_id: str):
101+
"""
102+
Delete a thread post.
103+
Args:
104+
post_id (str): The ID of the post to be deleted.
105+
"""
106+
self.forum_thread_page.click_on_delete_this_post_option(post_id)
107+
self.delete_thread_post_page.click_on_delete_button()
108+
109+
def report_thread_post(self, post_id: str):
110+
"""
111+
Report a thread post.
112+
Args:
113+
post_id (str): The ID of the post to be reported.
114+
"""
115+
self.forum_thread_page.click_on_report_abuse_option(post_id)
116+
72117
def delete_thread(self):
73118
"""
74119
Delete a thread.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from playwright_tests.core.basepage import BasePage
2+
3+
4+
class DeleteThreadPostPage(BasePage):
5+
"""
6+
This class contains the locators and actions for the Delete Thread Post page.
7+
"""
8+
9+
def __init__(self, page):
10+
super().__init__(page)
11+
self.delete_page_header = page.locator("article#confirm-delete h1")
12+
self.delete_button = page.locator("//input[@type='submit']")
13+
self.cancel_option = page.get_by_role("link", name="Cancel")
14+
15+
def click_on_delete_button(self):
16+
"""
17+
Click on the 'Delete' button.
18+
"""
19+
self._click(self.delete_button)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from playwright_tests.core.basepage import BasePage
2+
3+
4+
class EditThreadPostPage(BasePage):
5+
"""
6+
This class contains the locators and actions for the Edit Thread Post page.
7+
"""
8+
def __init__(self, page):
9+
super().__init__(page)
10+
self.edit_post_header = page.locator("div#edit-post h1")
11+
self.edit_post_textarea = page.locator("textarea#id_content")
12+
self.edit_post_cancel_button = page.get_by_role("link", name="Cancel")
13+
self.edit_post_update_post_button = page.get_by_role("button", name="Update post")
14+
self.edit_post_preview_button = page.get_by_role("button", name="Preview")
15+
16+
def add_text_inside_the_edit_post_textarea(self, text: str):
17+
"""
18+
Add text inside the edit post textarea.
19+
Args:
20+
text (str): The text to be added inside the edit post textarea.
21+
"""
22+
self._fill(self.edit_post_textarea, text)
23+
24+
def click_on_update_post_button(self):
25+
"""
26+
Click on the 'Update post' button.
27+
"""
28+
self._click(self.edit_post_update_post_button)

playwright_tests/pages/contribute/contribute_pages/contributor_discussions/forum_thread_page.py

Lines changed: 177 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime
2+
import re
23
from playwright_tests.core.basepage import BasePage
34
from playwright_tests.core.utilities import Utilities
45

@@ -56,24 +57,38 @@ def __init__(self, page):
5657
self.post_content = lambda post_id: page.locator(
5758
f"//li[@id='post-{post_id}']//div[@class='content']/p")
5859
self.thread_post = lambda post_id: page.locator(f"li#post-{post_id}")
60+
self.thread_post_by_content = lambda post_content: page.locator(
61+
f"//div[@class='content']/p[normalize-space(text())='{post_content}']")
62+
self.modified_by = lambda post_id: page.locator(f"li#post-{post_id} p.text-body-sm")
63+
self.quoted_thread_post_mention = lambda post_id: page.locator(
64+
f"li#post-{post_id} div.content em")
65+
self.quoted_thread_post_mention_link = lambda post_id: page.locator(
66+
f"li#post-{post_id} div.content em a")
67+
self.quoted_thread_post_quote = lambda post_id: page.locator(
68+
f"li#post-{post_id} div.content blockquote")
5969

6070
# Thread post more options locators
6171
self.post_3_dotted_menu = lambda post_id: page.locator(f"li#post-{post_id}").get_by_role(
6272
"button", name="more options")
73+
self.post_3_dotted_menu_expanded = lambda post_id: page.locator(
74+
f"//li[@id='post-{post_id}']//ul[contains(@id,'expand-datahasdropdown')]")
75+
self.private_message = lambda post_id: page.locator(
76+
f"li#post-{post_id} li.mzp-c-menu-list-item").get_by_role(
77+
"link", name="Private message")
6378
self.post_edit_this_post = lambda post_id: page.locator(
64-
f"li#post-{post_id} ul#expand-expand-datahasdropdown-0 li").get_by_role(
79+
f"li#post-{post_id} li.mzp-c-menu-list-item").get_by_role(
6580
"link", name="Edit this post")
6681
self.delete_this_post = lambda post_id: page.locator(
67-
f"li#post-{post_id} ul#expand-expand-datahasdropdown-0 li").get_by_role(
82+
f"li#post-{post_id} li.mzp-c-menu-list-item").get_by_role(
6883
"link", name="Delete this post")
6984
self.quote_this_post = lambda post_id: page.locator(
70-
f"li#post-{post_id} ul#expand-expand-datahasdropdown-0 li").get_by_role(
85+
f"li#post-{post_id} li.mzp-c-menu-list-item").get_by_role(
7186
"link", name="Quote")
7287
self.report_this_post = lambda post_id: page.locator(
73-
f"li#post-{post_id} ul#expand-expand-datahasdropdown-0 li").get_by_role(
88+
f"li#post-{post_id} li.mzp-c-menu-list-item").get_by_role(
7489
"link", name="Report Abuse")
7590
self.link_this_post = lambda post_id: page.locator(
76-
f"li#post-{post_id} ul#expand-expand-datahasdropdown-0 li").get_by_role(
91+
f"li#post-{post_id} li.mzp-c-menu-list-item").get_by_role(
7792
"link", name="Link to this post")
7893

7994
# Post a reply locators
@@ -118,6 +133,26 @@ def is_thread_post_visible(self, post_id: str) -> bool:
118133
"""
119134
return self._is_element_visible(self.thread_post(post_id))
120135

136+
def is_thread_post_by_name_visible(self, post_name: str) -> bool:
137+
"""
138+
Check if a specific thread post by name is visible.
139+
Args:
140+
post_name (str): The name of the post.
141+
Returns:
142+
bool: True if the post is visible, False otherwise.
143+
"""
144+
return self._is_element_visible(self.thread_post_by_content(post_name))
145+
146+
def get_modified_by_text(self, post_id: str) -> str:
147+
"""
148+
Get the modified by text for a specific post.
149+
Args:
150+
post_id (str): The ID of the post.
151+
Returns:
152+
str: The modified by text.
153+
"""
154+
return self._get_text_of_element(self.modified_by(post_id))
155+
121156
def is_edit_thread_title_option_visible(self) -> bool:
122157
"""
123158
Check if the edit thread title option is visible.
@@ -299,3 +334,140 @@ def click_on_contributor_discussions_side_navbar_item(self, item_name: str):
299334
item_name (str): The name of the item to click on.
300335
"""
301336
self._click(self.contributor_discussions_side_navbar_item(item_name))
337+
338+
def click_on_3_dotted_menu(self, post_id: str):
339+
"""
340+
Click on the 3-dotted menu for a specific post.
341+
Args:
342+
post_id (str): The ID of the post.
343+
"""
344+
self._click(self.post_3_dotted_menu(post_id),
345+
expected_locator=self.post_3_dotted_menu_expanded(post_id))
346+
347+
def click_on_edit_this_post_option(self, post_id: str):
348+
"""
349+
1. Click on the "Edit this post" option for a specific post.
350+
2. Click on the "Edit this post" option in the 3-dotted menu of the post.
351+
Args:
352+
post_id (str): The ID of the post.
353+
"""
354+
self.click_on_3_dotted_menu(post_id)
355+
self._click(self.post_edit_this_post(post_id))
356+
357+
def is_edit_this_post_option_displayed(self, post_id: str):
358+
"""
359+
Check if the "Edit this post" option is displayed in the 3-dotted menu of a specific post.
360+
Args:
361+
post_id (str): The ID of the post.
362+
Returns:
363+
bool: True if the option is displayed, False otherwise.
364+
"""
365+
self.click_on_3_dotted_menu(post_id)
366+
return self._is_element_visible(self.post_edit_this_post(post_id))
367+
368+
def is_delete_this_post_option_displayed(self, post_id: str):
369+
"""
370+
Check if the "Delete this post" option is displayed in the 3-dotted menu of a specific
371+
post.
372+
Args:
373+
post_id (str): The ID of the post.
374+
Returns:
375+
bool: True if the option is displayed, False otherwise.
376+
"""
377+
self.click_on_3_dotted_menu(post_id)
378+
return self._is_element_visible(self.delete_this_post(post_id))
379+
380+
def click_on_quote_option(self, post_id: str):
381+
"""
382+
Click on the "Quote" option for a specific post.
383+
Args:
384+
post_id (str): The ID of the post.
385+
"""
386+
self.click_on_3_dotted_menu(post_id)
387+
self._click(self.quote_this_post(post_id))
388+
389+
def click_on_delete_this_post_option(self, post_id: str):
390+
"""
391+
Click on the "Delete this post" option for a specific post.
392+
Args:
393+
post_id (str): The ID of the post.
394+
"""
395+
self.click_on_3_dotted_menu(post_id)
396+
self._click(self.delete_this_post(post_id))
397+
398+
def click_on_private_message_option(self, post_id: str):
399+
"""
400+
Click on the "Private message" option for a specific post.
401+
Args:
402+
post_id (str): The ID of the post.
403+
"""
404+
self.click_on_3_dotted_menu(post_id)
405+
self._click(self.private_message(post_id))
406+
407+
def is_quote_option_displayed(self, post_id: str) -> bool:
408+
"""
409+
Check if the "Quote" option is displayed in the 3-dotted menu of a specific post.
410+
Returns:
411+
bool: True if the option is displayed, False otherwise.
412+
"""
413+
self.click_on_3_dotted_menu(post_id)
414+
return self._is_element_visible(self.quote_this_post(post_id))
415+
416+
def click_on_report_abuse_option(self, post_id: str):
417+
"""
418+
Click on the "Report Abuse" option for a specific post.
419+
Args:
420+
post_id (str): The ID of the post.
421+
"""
422+
self.click_on_3_dotted_menu(post_id)
423+
self._click(self.report_this_post(post_id))
424+
425+
def click_on_link_to_this_post_option(self, post_id: str) -> str:
426+
"""
427+
Click on the "Link to this post" option for a specific post.
428+
Args:
429+
post_id (str): The ID of the post.
430+
Returns:
431+
str: The ID of the post.
432+
"""
433+
self.click_on_3_dotted_menu(post_id)
434+
self._click(self.link_this_post(post_id))
435+
436+
return re.search(r'post-(\d+)', self.utilities.get_page_url()).group(1)
437+
438+
def is_report_abuse_option_displayed(self, post_id: str) -> bool:
439+
"""
440+
Check if the "Report Abuse" option is displayed in the 3-dotted menu of a specific post.
441+
Args:
442+
post_id (str): The ID of the post.
443+
Returns:
444+
bool: True if the option is displayed, False otherwise.
445+
"""
446+
self.click_on_3_dotted_menu(post_id)
447+
return self._is_element_visible(self.report_this_post(post_id))
448+
449+
def get_thread_post_mention_text(self, post_id: str) -> str:
450+
"""
451+
Get the thread post mention text for a specific post.
452+
Args:
453+
post_id (str): The ID of the post.
454+
Returns:
455+
str: The thread post mention text.
456+
"""
457+
return self._get_text_of_element(self.quoted_thread_post_mention(post_id))
458+
459+
def click_on_post_mention_link(self, post_id: str):
460+
"""
461+
Click on the post mention link.
462+
"""
463+
self._click(self.quoted_thread_post_mention_link(post_id))
464+
465+
def get_thread_post_quote_text(self, post_id: str) -> str:
466+
"""
467+
Get the thread post quote text for a specific post.
468+
Args:
469+
post_id (str): The ID of the post.
470+
Returns:
471+
str: The thread post quote text.
472+
"""
473+
return self._get_text_of_element(self.quoted_thread_post_quote(post_id))

playwright_tests/pages/sumo_pages.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
from playwright_tests.pages.common_elements.common_web_elements import CommonWebElements
2424
from playwright_tests.pages.contribute.contribute_pages.contributor_discussions.\
2525
contributor_discussions_page import ContributorDiscussionPage
26+
from playwright_tests.pages.contribute.contribute_pages.contributor_discussions.\
27+
delete_thread_post_page import DeleteThreadPostPage
28+
from playwright_tests.pages.contribute.contribute_pages.contributor_discussions.\
29+
edit_thread_post_page import EditThreadPostPage
2630
from playwright_tests.pages.contribute.contribute_pages.contributor_discussions.\
2731
edit_thread_title_page import EditThreadTitle
2832
from playwright_tests.pages.contribute.contribute_pages.contributor_discussions.\
@@ -202,6 +206,8 @@ def __init__(self, page: Page):
202206
self.forum_discussions_page = ForumDiscussionsPage(page)
203207
self.new_thread_page = NewThreadPage(page)
204208
self.edit_thread_title_page = EditThreadTitle(page)
209+
self.edit_post_thread_page = EditThreadPostPage(page)
210+
self.delete_thread_post_page = DeleteThreadPostPage(page)
205211
self.forum_thread_page = ForumThreadPage(page)
206212

207213
# Discussion Threads flow.

0 commit comments

Comments
 (0)